package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 激光导弹<br/>
 * 对敌方随机两个目标发射导弹，造成{0=130#1}%技能伤害，若有目标死亡则导弹将爆炸，额外对全体敌方造成{1=70#0.5}%技能伤害（若两个目标都死亡则只生效1次）
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90132 extends CombatSkill {

	public COMBAT_SKILL_90132(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		CombatUnit source = action.unit;
		List<CombatUnit> targets = action.target.getUnitsRandomly(2);
		float rate = skill.getParameter(0) / GameStaticConfig.percentBase;
		boolean hasDied = false;
		for (int i = 0; i < targets.size(); i++) {
			CombatUnit target = targets.get(i);
			if (!target.isDied()) {
				ActionEffect eff = action.addTarget(target);
				CombatUtils.calcMagicAttack(eff, rate);
				if (eff.getUnit().isDied()) {
					hasDied = true;
				}
			}
		}
		if (hasDied) {
			rate = skill.getParameter(1) / GameStaticConfig.percentBase;
			targets = action.target.all();
			Action newAct = null;
			for (int i = 0; i < targets.size(); i++) {
				CombatUnit target = targets.get(i);
				if (!target.isDied()) {
					if (newAct == null) {
						newAct = new Action(source);
						action.ref().add(newAct);
					}
					ActionEffect eff = newAct.addTarget(target);
					CombatUtils.calcMagicAttack(eff, rate);
				}
			}
		}
	}
	
}
